home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / ge_cool.lha / GE_COOL2.1 / man / oldman3 / Rational.3T < prev    next >
Text File  |  1992-06-26  |  10KB  |  314 lines

  1. .TH RATIONAL
  2. .SH NAME
  3. Rational  Infinite precision rational numbers
  4. .SH SYNOPSIS
  5. #include <cool/Rational.h>
  6. .SH DESCRIPTION
  7. The 
  8.  Rational
  9. class provides infinite precision rational numbers and arithmetic 
  10. using the built-in 
  11.  long 
  12. type for the numerator and denominator objects. 
  13. Consequently, a rational object will grow in 32-bit chunks as necessary. 
  14. Implicit conversion to the system-defined types 
  15.  short , 
  16.  int , 
  17.  long , 
  18.  float , 
  19. and 
  20.  double 
  21. is supported by overloaded operator member functions. However, 
  22. arithmetic operations on rational objects are slower than the built-in integer 
  23. types.
  24. .PP
  25. The 
  26.  Rational 
  27. class implements common arithmetic exception handling and provides 
  28. application support for detecting negative infinity, positive infinity, 
  29. overflow, and underflow that may result from an operation. If one of these 
  30. conditions is detected or if an attempt to convert from a 
  31.  Rational 
  32. with no 
  33. value to a built-in type is made, an exception is raised. The programmer can 
  34. provide an exception handler at runtime to take care of this problem. If no 
  35. such handler is available, an error message is printed and program execution 
  36. terminates. See Section 13 for more information on the cool exception handling mechanism.
  37. .SH Base Classes
  38.  
  39. .SH Friend Classes
  40. None
  41. .SH Constructors
  42. .TP
  43.  inline Rational ();
  44. Simple constructor to create a new rational object.
  45. .TP
  46. \f3Rational (long \f2n\f3, long \f2d \f1= 1\f3);\f1
  47. Constructor that specifies an integer numerator and optional denominator 
  48. arguments to create a new rational object.
  49. .TP
  50. \f3Rational (const Rational& \f2r\f3);\f1
  51. Constructor that takes a reference to an existing rational object and creates a 
  52. new object with the same value.
  53. .SH Member Functions
  54. .TP
  55.  inline long ceiling () const;
  56. Returns an integer that represents the value of the rational object truncated 
  57. towards positive infinity.
  58. .TP
  59.  inline long denominator () const;
  60. Returns the denominator value of the object.
  61. .TP
  62.  inline operator double ();
  63. Overloaded operator to provide implicit conversion between rational objects and 
  64. the built-in 
  65.  double 
  66. type when appropriate.
  67. .TP
  68.  operator float ();
  69. Overloaded operator to provide implicit conversion between rational objects and 
  70. the built-in 
  71.  float 
  72. type when appropriate.
  73. .TP
  74.  inline long floor () const;
  75. Returns an integer that represents the value of the rational object truncated 
  76. towards negative infinity.
  77.  
  78. .TP
  79.  operator int ();
  80. Overloaded operator to provide implicit conversion between rational objects and 
  81. the built-in 
  82.  int 
  83. type when appropriate.
  84. .TP
  85.  Rational& invert ();
  86. Returns a reference to the inverse of the rational number object.
  87. .TP
  88.  operator long ();
  89. Overloaded operator to provide implicit conversion between rational objects and 
  90. the built-in 
  91.  long 
  92. type when appropriate.
  93. .TP
  94.  inline long numerator () const;
  95. Returns the numerator value of the object.
  96. .TP
  97.  inline Rational operator\-();
  98. Overloads the unary minus operator for the 
  99.  Rational 
  100. class and returns a new 
  101. object whose value is the negated value of the object. If the operation results 
  102. in an arithmetic error of some type, the appropriate exception is raised.
  103. .TP
  104. \f3inline Rational& operator= (const Rational& \f2r\f3);\f1
  105. Overloads the assignment operator for the 
  106.  Rational 
  107. class and assigns one 
  108. rational number to have the value of another. A reference to the updated object 
  109. is returned.
  110. .TP
  111. \f3void operator+= (const Rational& \f2r\f3);\f1
  112. Overloads the addition-with-assignment operator for the 
  113.  Rational 
  114. class. If the 
  115. operation results in an arithmetic error of some type, the appropriate 
  116. exception is raised.
  117. .TP
  118. \f3inline void operator\-= (const Rational& \f2r\f3);\f1
  119. Overloads the subtraction-with-assignment operator for the 
  120.  Rational 
  121. class. If 
  122. the operation results in an arithmetic exception of some type, the appropriate 
  123. exception is raised.
  124. .TP
  125. \f3void operator*= (const Rational& \f2r\f3);\f1
  126. Overloads the multiplication-with-assignment operator for the 
  127.  Rational 
  128. class. 
  129. If the operation results in an arithmetic error of some type, the appropriate 
  130. exception is raised.
  131. .TP
  132. \f3inline void operator/= (const Rational& \f2r\f3);\f1
  133. Overloads the division-with-assignment operator for the 
  134.  Rational 
  135. class. If the 
  136. operation results in an arithmetic error of some type, the appropriate 
  137. exception is raised.
  138. .TP
  139. \f3void operator%= (const Rational& \f2r\f3);\f1
  140. Overloads the modulus with assignment operator for the 
  141.  Rational 
  142. class. If the 
  143. operation results in an arithmetic error of some type, the appropriate 
  144. exception is raised.
  145. .TP
  146.  inline Boolean operator!() const;
  147. Overloads the logical NOT operator for the 
  148.  Rational 
  149. class and returns 
  150.  
  151.  TRUE
  152. if 
  153. the complex number has a zero value; otherwise, this function returns 
  154.  
  155.  FALSE .
  156. .TP
  157.  inline Rational& operator++ ();
  158. Provides an increment capability for the 
  159.  Rational 
  160. class. If the operation 
  161. results in an arithmetic error of some type, the appropriate exception is 
  162. raised.  A reference to the modified Rational object is returned.
  163. .TP
  164.  inline Rational& operator\-\|\- ();
  165. Provides a decrement capability for the 
  166.  Rational 
  167. class. If the operation 
  168. results in an arithmetic error of some type, the appropriate exception is 
  169. raised.  A reference to the modified Rational object is returned.
  170. .TP
  171. \f3inline Boolean operator== (const Rational& \f2r\f3) const;\f1
  172. Overloads the equality operator for the 
  173.  Rational 
  174. class. This function returns 
  175.  
  176.  TRUE 
  177. if the rational numbers have the same value; otherwise, this function 
  178. returns 
  179.  
  180.  FALSE .
  181.  
  182. .TP
  183. \f3inline Boolean operator!= (const Rational& \f2r\f3) const;\f1
  184. Overloads the inequality operator for the 
  185.  Rational 
  186. class. This function returns 
  187.  
  188.  TRUE
  189. if the rational numbers have different values; otherwise, this function 
  190. returns 
  191.  
  192.  FALSE .
  193. .TP
  194. \f3Boolean operator< (const Rational& \f2r\f3) const;\f1
  195. Overloads the less-than-operator for the 
  196.  Rational 
  197. class and returns 
  198.  
  199.  TRUE 
  200. if the 
  201. object is less than the specified argument; otherwise, this function returns 
  202.  
  203.  FALSE .
  204. .TP
  205. \f3inline Boolean operator<= (const Rational& \f2r\f3) const;\f1
  206. Overloads the less-than-or-equal operator for the 
  207.  Rational 
  208. class. This function 
  209. returns 
  210.  
  211.  TRUE 
  212. if the object is less than or equal to the value of the specified 
  213. argument; otherwise, this function returns 
  214.  
  215.  FALSE .
  216. .TP
  217. \f3Boolean operator> (const Rational& \f2r\f3) const;\f1
  218. Overloads the greater-than operator for the 
  219.  Rational 
  220. class and returns 
  221.  
  222.  TRUE 
  223. if 
  224. the object is greater than the specified argument; otherwise, this function 
  225. returns 
  226.  
  227.  FALSE .
  228. .TP
  229. \f3inline Boolean operator>= (const Rational& \f2r\f3) const;\f1
  230. Overloads the greater-than-or-equal operator for the 
  231.  Rational 
  232. class. This 
  233. function returns 
  234.  
  235.  TRUE 
  236. if the object is greater than or equal to the value of 
  237. the specified argument ; otherwise, this function returns 
  238.  
  239.  FALSE .
  240. .TP
  241.  long round () const;
  242. Returns an integer that represents the value of the rational object truncated 
  243. towards the nearest integer.
  244. .TP
  245.  operator short ();
  246. Overloaded operator to provide implicit conversion between rational objects and 
  247. the built-in 
  248.  short 
  249. type when appropriate.
  250. .TP
  251.  inline N_State status () const;
  252. Returns the numerical exception state of the rational object.
  253. .TP
  254.  inline long truncate () const;
  255. Returns an integer that represents the value of the rational object truncated 
  256. towards zero.
  257. .SH Friend Functions
  258. .TP
  259. \f3friend Rational operator+ (const Rational& \f2r1\f3, const Rational& \f2r2\f3);\f1
  260. Overloads the addition operator for the 
  261.  Rational 
  262. class. A new rational object 
  263. is returned as the result. If the operation results in an arithmetic error of 
  264. some type, the appropriate exception is raised.
  265. .TP
  266. \f3inline friend Rational operator\- (const Rational& \f2r1\f3, const Rational& \f2r2\f3);\f1
  267. Overloads the subtraction operator to provide subtraction for the 
  268.  Rational 
  269. class. A new rational object is returned as the result. If the operation 
  270. results in an arithmetic error of some type, the appropriate exception is 
  271. raised.
  272. .TP
  273. \f3friend Rational operator* (const Rational& \f2r1\f3, const Rational& \f2r2\f3);\f1
  274. Overloads the multiplication operator for the 
  275.  Rational 
  276. class. A new rational 
  277. object is returned as the result. If the operation results in an arithmetic 
  278. error of some type, the appropriate exception is raised.
  279. .TP
  280. \f3inline friend Rational operator/ (const Rational& \f2r1\f3, const Rational& \f2r2\f3);\f1
  281. Overloads the division operator for the 
  282.  Rational 
  283. class. A new rational object 
  284. is returned as the result. If the operation results in an arithmetic error of 
  285. some type, the appropriate exception is raised.
  286. .TP
  287. \f3friend Rational operator% (const Rational& \f2r1\f3, const Rational& \f2r2\f3);\f1
  288. Overloads the modulus operator for the 
  289.  Rational 
  290. class. A new rational object is 
  291. returned as the result. If the operation results in an arithmetic error of some 
  292. type, the appropriate exception is raised.
  293.  
  294. .TP
  295. \f3inline friend ostream& operator<< (ostream& \f2os\f3, const Rational& \f2r\f3);\f1
  296. Overloads the output operator for a reference to a rational object to provide a 
  297. formatted output capability.
  298. .TP
  299. \f3inline friend ostream& operator<< (ostream& \f2os\f3, const Rational* \f2r\f3);\f1
  300. Overloads the output operator for a pointer to a rational object to provide a 
  301. formatted output capability.
  302. .SH COPYRIGHT
  303.  
  304. Copyright (C) 1991 Texas Instruments Incorporated.
  305.  
  306. Permission is granted to any individual or institution to use, copy, modify,
  307. and distribute this software, provided that this complete copyright and
  308. permission notice is maintained, intact, in all copies and supporting
  309. documentation.
  310.  
  311. Texas Instruments Incorporated provides this software "as is" without
  312. express or implied warranty.
  313.  
  314.